package com.example.yifei.ui.page.common

import androidx.compose.foundation.ExperimentalFoundationApi
import androidx.compose.material.ExperimentalMaterialApi
import androidx.compose.material.Scaffold
import androidx.compose.material.SnackbarHost
import androidx.compose.material.rememberScaffoldState
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.ui.ExperimentalComposeUiApi
import androidx.navigation.compose.currentBackStackEntryAsState
import androidx.navigation.compose.rememberNavController
import coil.annotation.ExperimentalCoilApi
import com.example.yifei.ui.page.widgets.AppSnackBar
import com.example.yifei.ui.page.widgets.BottomNavBarView
import com.google.accompanist.pager.ExperimentalPagerApi


/**
 * @Author: zhudaihao
 * @Date: 2022/5/6
 * @Describe: 脚手架和配置路由
 */

@ExperimentalCoilApi
@ExperimentalMaterialApi
@ExperimentalComposeUiApi
@ExperimentalFoundationApi
@ExperimentalPagerApi
@Composable
fun AppScaffold() {
    val navCtrl = rememberNavController()
    val navBackStackEntry by navCtrl.currentBackStackEntryAsState()
    val currentDestination = navBackStackEntry?.destination
    val scaffoldState = rememberScaffoldState()

    Scaffold(
        snackbarHost = {
            SnackbarHost(
                hostState = scaffoldState.snackbarHostState
            ) { data ->
                println("actionLabel = ${data.actionLabel}")
                AppSnackBar(data = data)
            }
        },


        content = RouteManger(navCtrl),


        bottomBar = {
            when (currentDestination?.route) {
                RouteName.HOME -> BottomNavBarView(navCtrl = navCtrl)
                RouteName.PRODUCTION_DEMAND -> BottomNavBarView(navCtrl = navCtrl)
                RouteName.PRODUCTION_WORK_ORDER -> BottomNavBarView(navCtrl = navCtrl)
                RouteName.PURCHASE_LIST -> BottomNavBarView(navCtrl = navCtrl)
                RouteName.PROFILE -> BottomNavBarView(navCtrl = navCtrl)
            }
        }

    )
}


